﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Batty
{
    public class Lego
    {
        private Pondhawk game;
        private Model model;
        public Vector3 position = new Vector3(0, 0, 0);

        public Lego(Pondhawk game)
        {

            this.game = game;

        }

        public void LoadContent(ContentManager content)
        {
            model = content.Load<Model>("Lego");

        }

        public void Draw(GraphicsDeviceManager graphics, GameTime gameTime)
        {
            //Matrix transform = Matrix.CreateTranslation(position)*Matrix.CreateScale(10f);
            Matrix transform = Matrix.CreateScale(5f);
            DrawModel(graphics, model, transform);
            //  DrawModel(graphics, model, Matrix.Identity);

        }

        public BoundingSphere getSphere()
        {
            BoundingSphere sphere = model.Meshes[0].BoundingSphere;
            sphere = sphere.Transform(model.Bones[0].Transform);
            sphere.Center += position;
            return sphere;
        }

        private void DrawModel(GraphicsDeviceManager graphics, Model model, Matrix world)
        {
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * world;
                    effect.View = game.Camera.View;
                    effect.Projection = game.Camera.Projection;
                }
                mesh.Draw();
            }
        }
    }


}

